/*
*
*    LocalConnectionService - Unlimited RPC functionality through LocalConnection.
*    Copyright (C) 2009 BLITZ Digital Studios LLC d/b/a BLITZ Agency.
*
*    This library is free software; you can redistribute it and/or modify it 
*    under the terms of the GNU Lesser General Public License as published
*    by the Free Software Foundation; either version 2.1 of the License, or 
*    (at your option) any later version.
*
*    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
*    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
*    PURPOSE. See the GNU Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public License along 
*    with this library; if not, write to the Free Software Foundation, Inc.,
*    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*
*    BLTIZ Digital Studios LLC, 3415 S. Sepulveda BLVD, Ste 500, Los Angeles CA, 90034
*    http://www.blitzagency.com
*    http://labs.blitzagency.com
*
*	 Author: Evan Gifford - egifford@blitzagency.com
*
*/
package com.blitzagency.rpc
{

	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.core.mx_internal;
	import mx.rpc.AsyncToken;
	import mx.rpc.Fault;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	use namespace mx_internal;	
		
	public class ASyncTokenProxy extends EventDispatcher
	{
		
		public var token:AsyncToken;	
			
		public function resultHandler(resultObject:*):void{
			var resultEvent:ResultEvent = ResultEvent.createEvent(resultObject);					
			token.applyResult( resultEvent );
			
			dispatchEvent( new Event( Event.COMPLETE ) );
		}
		
		public function faultHandler(result:*):void{
			
			var fault:Fault = new Fault("0001",result.type);
			
			var faultEvent:FaultEvent = FaultEvent.createEvent(fault,token,token.message);
			token.applyFault( faultEvent );
			
			dispatchEvent( new Event( Event.COMPLETE ) );
		}

	}
}